<?php

namespace Admin\Forms;

/**
 * Description of Product
 *
 * @author nofear
 */
class Category {

    private $view;
    private $Object;
    private $methods;
    private $annotations = array();

    public function __construct($Object = null) {
        $this->Object = $Object;
        $this->methods = $this->getMethods($this->Object);
        $this->EntityManager = \Shared\Application::getInstance()->getEntityManager();

        $this->view = new \System\Template('@forms/category.twig');
    }

    public function render() {
        foreach ($this->methods as $method => $value) {
            $this->view->$method = $value;
        }

        $this->view->Object = $this->Object;
        
        return $this->view->paste();
    }

    private function getMethods($Object) {
        $methods = get_class_methods($Object);
        $tmp = array();

        foreach ($methods as $method) {
            if (substr($method, 0, 3) == 'get') {
                if (is_object($Object->{$method}()) || isset($this->annotations[strtolower(substr($method, 3))])) {
                    if (is_object($Object->{$method}())) {
                        $tmp[lcfirst(substr($method, 3))] = $Object->{$method}();
                    } else {
                        $tmp[lcfirst(substr($method, 3))] = new $this->annotations[strtolower(substr($method, 3))] ;
                    }
                } else {
                    $tmp[lcfirst(substr($method, 3))] = $Object->{$method}();
                }
            }
        }

        return $tmp;
    }

}
